<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

Route::group([
    'prefix' => 'v1',
], function ($router) {
    Route::post('auth/login', 'AuthController@login');
    Route::get('auth/captcha', 'AuthController@captcha');
    Route::any('test1', 'TestController@test');
});

Route::group([
    'prefix' => 'v1',
    'middleware' => ['auth.jwt','auth.check_permission']
], function ($router) {
    Route::any('test', 'TestController@test');

    Route::post('files', 'FileController@upload');
    Route::delete('files', 'FileController@delete');

    Route::delete('auth/logout', 'AuthController@logout');
    Route::post('refresh', 'AuthController@refresh');
    Route::get('users/me', 'AuthController@me');
    //路由
    Route::get('menus/routes', 'MenuController@routes');

    //部门
    Route::get('dept/options', 'DeptController@options');
    Route::get('dept', 'DeptController@tree');
    Route::post('dept', 'DeptController@store')->name('sys:dept:add');
    Route::get('dept/{id}/form', 'DeptController@detail');
    Route::put('dept/{id}', 'DeptController@update')->name('sys:dept:update');
    Route::delete('dept/{id}', 'DeptController@destroy')->name('sys:dept:delete');

    //角色
    Route::get('roles/options', 'RoleController@options');
    Route::get('roles/page', 'RoleController@index');
    Route::post('roles', 'RoleController@store')->name('sys:role:add');
    Route::put('roles/{id}', 'RoleController@update')->name('sys:role:edit');
    Route::delete('roles/{id}', 'RoleController@destroy')->name('sys:role:delete');
    Route::get('roles/{id}/menuIds', 'RoleController@getMenuIds');
    Route::put('roles/{id}/menus', 'RoleController@setMenuIds');
    Route::get('roles/{id}/form', 'RoleController@detail');
    //菜单
    Route::get('menus/options', 'MenuController@options');
    Route::post('menus', 'MenuController@store')->name('sys:menu:add');
    Route::put('menus/{id}', 'MenuController@update')->name('sys:menu:edit');
    Route::get('menus', 'MenuController@tree');
    Route::get('menus/{id}/form', 'MenuController@detail');
    //用户
    Route::get('users/page', 'UserController@index')->name('sys:user:query');
    Route::post('users', 'UserController@store')->name('sys:user:add');
    Route::get('users/{id}/form', 'UserController@detail');
    Route::patch('users/{id}/password', 'UserController@updatePassword')->name('sys:user:password:reset');
    Route::put('users/{id}', 'UserController@update')->name('sys:user:edit');
    Route::delete('users/{id}', 'UserController@destroy')->name('sys:user:delete');
    //字典
    Route::get('dict/{type}/options', 'DictController@options');
    Route::get('dict/page', 'DictController@index');
    Route::post('dict', 'DictController@store')->name('sys:dict:add');
    Route::put('dict/{id}', 'DictController@update')->name('sys:dict:edit');
    Route::delete('dict/{id}', 'DictController@destroy')->name('sys:dict:delete');
    Route::get('dict/{id}/form', 'DictController@detail');
});

